package com.gao.y_linkedtransferqueue;

import java.util.concurrent.LinkedTransferQueue;

/**
 * @author gao
 * @time 2021/04/20 22:33:48
 */
public class App {
    public static void main(String[] args) throws InterruptedException {
        LinkedTransferQueue queue = new LinkedTransferQueue();

        Thread th = new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + " transfer 开始");
                queue.transfer(1);
                System.out.println(Thread.currentThread().getName() + "transfer 结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread th2 = new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + " take 开始");
                queue.transfer(2);
                System.out.println(Thread.currentThread().getName() + "take 结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });


        Thread th3 = new Thread(() -> {
            try {
                System.out.println(Thread.currentThread().getName() + " take 开始");
                queue.take();
                System.out.println(Thread.currentThread().getName() + "take 结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });


//        th.start();
//        Thread.sleep(3000);
//        th2.start();
//        Thread.sleep(3000);
        th3.start();
    }
}
